﻿@model Coslen.TahorCRM.Domain.Entities.ViewModels.Searching.GroupContactSearchViewModel
@{
    ViewBag.Title = "EditList";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script type="text/javascript">
    function suspendMembership(groupContactId) {
        $("td[data-groupcontactid=" + groupContactId + "] input[name$=IsSuspended]").val("true");
    }
</script>
<h2>Edit Membership List</h2>
@using (Html.BeginForm())
{
    <fieldset>
        @{
            var numberOfColumns = 3;
            var numberOfContacts = Model.SearchResults.Count;
            int numberInEachColumn = numberOfContacts/numberOfColumns;

            <table>
                @for (int index = 0; index < numberOfContacts; index = index + 3)
                {
                    <tr>
                        @if (index < numberOfContacts)
                        {
                            var groupContact = Model.SearchResults.ToArray()[index];
                            <td class="tdGroupContactFullName" data-groupcontactid="@groupContact.GroupContactId">
                                @groupContact.Contact.LastName, @groupContact.Contact.FirstName
                                <input type="hidden" name="[@index].GroupId" value="@groupContact.GroupId" />
                                <input type="hidden" name="[@index].ContactId" value="@groupContact.ContactId" />
                                <input type="hidden" name="[@index].GroupContactId" value="@groupContact.GroupContactId" />
                                <input type="hidden" name="[@index].IsSuspended" value="@groupContact.IsSuspended" />
                                <input type="hidden" name="[@index].SuspendedAt" value="@groupContact.SuspendedAt" />
                            </td>
                            <td class="tdGroupContactControl">
                                <img src="@Url.Content("~/Content/images/minus.png")" alt="suspend" width="12px" height="12px" onclick="  suspendMembership(@groupContact.GroupContactId);"/>
                            </td>
                        }
                        else
                        {
                            <td class="tdGroupContactFullName"></td>
                            <td class="tdGroupContactControl"></td>
                        }
                
                        @if (index + 1 < numberOfContacts)
                        {
                            var groupContact = Model.SearchResults.ToArray()[index + 1];
                            <td class="tdGroupContactFullName" data-groupcontactid="@groupContact.GroupContactId">
                                @groupContact.Contact.LastName, @groupContact.Contact.FirstName
                                <input type="hidden" name="[@index].GroupId" value="@groupContact.GroupId" />
                                <input type="hidden" name="[@index].ContactId" value="@groupContact.ContactId" />
                                <input type="hidden" name="[@index].GroupContactId" value="@groupContact.GroupContactId" />
                                <input type="hidden" name="[@index].IsSuspended" value="@groupContact.IsSuspended" />
                                <input type="hidden" name="[@index].SuspendedAt" value="@groupContact.SuspendedAt" />
                            </td>
                            <td class="tdGroupContactControl">
                                <img src="@Url.Content("~/Content/images/minus.png")" alt="suspend" width="12px" height="12px" onclick="   suspendMembership(@groupContact.GroupContactId);"/>
                            </td>
                        }
                        else
                        {
                            <td class="tdGroupContactFullName"></td>
                            <td class="tdGroupContactControl"></td>
                        }
                        @if (index + 2 < numberOfContacts)
                        {
                            var groupContact = Model.SearchResults.ToArray()[index + 2];
                            <td class="tdGroupContactFullName" data-groupcontactid="@groupContact.GroupContactId">
                                @groupContact.Contact.LastName, @groupContact.Contact.FirstName
                                <input type="hidden" name="[@index].GroupId" value="@groupContact.GroupId" />
                                <input type="hidden" name="[@index].ContactId" value="@groupContact.ContactId" />
                                <input type="hidden" name="[@index].GroupContactId" value="@groupContact.GroupContactId" />
                                <input type="hidden" name="[@index].IsSuspended" value="@groupContact.IsSuspended" />
                                <input type="hidden" name="[@index].SuspendedAt" value="@groupContact.SuspendedAt" />
                            </td>
                            <td class="tdGroupContactControl">
                                <img src="@Url.Content("~/Content/images/minus.png")" alt="suspend" width="12px" height="12px" onclick="  suspendMembership(@groupContact.GroupContactId);"/>
                            </td>
                        }
                        else
                        {
                            <td class="tdGroupContactFullName"></td>
                            <td class="tdGroupContactControl"></td>
                        }
                    </tr>
                }
            </table>

            <p>
                <input type="submit" value="Save" />
            </p>
        }
    </fieldset>
    
}